<!--
 * @Description: 招聘 岗位审核详情
 * @Author: liyujie
 * @Date: 2021/08/03
 * @Last Modified by: liyujie
 * @Last Modified time: 2021/08/03
-->
<template>
    <div class="wrapper">
        <div class="content-wrapper">
            <!-- header -->
            <div class="header">
                <div class="header-title">
                    岗位信息
                </div>
                <div
                    class="option-button"
                    v-if="formData.verify === 0"
                >
                    <div
                        class="button-item"
                        style="color: #20A0FF"
                        @click="showVerifyDialog(1)"
                    >
                        通过
                    </div>
                    <div
                        class="button-item"
                        style="color: #F53341"
                        @click="showVerifyDialog(-1)"
                    >
                        不通过
                    </div>
                    <div
                        class="button-item last"
                        style="color: #666666"
                        @click="handleRoute('recruitPostList')"
                    >
                        返回
                    </div>
                </div>
                <div
                    class="back"
                    v-else
                    @click="handleRoute('recruitPostList')"
                >
                    返回
                </div>
            </div>
            <!-- /header -->
            <div class="form-wrapper">
                <!-- 审核状态显示区域 -->
                <div class="status-view">
                    <template v-if="formData.verify === 0">
                        <div class="status-text warning">待审核</div>
                        <div class="status-desc-text">商家已提交岗位信息，请尽快审核~</div>
                    </template>
                    <template v-if="formData.verify === 1">
                        <div class="status-text success">审核通过</div>
                        <div class="status-desc-text">审核时间：{{ formData.verify_time * 1000 | dateFormatter('yyyy/MM/dd HH:mm:ss') }}</div>
                    </template>
                    <template v-if="formData.verify === -1">
                        <div class="status-text danger">审核不通过</div>
                        <div class="status-desc-text">不通过原因：{{ formData.verify_fail_reason }}</div>
                    </template>
                    <div class="status-desc-text">提交审核时间：{{ formData.submit_time * 1000 | dateFormatter('yyyy/MM/dd HH:mm:ss') }}</div>
                </div>
                <el-form>
                    <!--基本信息区域-->
                    <div class="form-view">
                        <div class="form-title">
                            基本信息
                        </div>
                        <el-form inline>
                            <el-row>
                                <el-col :span="6">
                                    <el-form-item label="公司名称：">
                                        {{ formData.company_name }}
                                    </el-form-item>
                                </el-col>
                                <el-col :span="6">
                                    <el-form-item label="招聘类型：">
                                        <template v-if="formData.type === 1">实习生</template>
                                        <template v-if="formData.type === 2">毕业校招</template>
                                    </el-form-item>
                                </el-col>
                                <el-col :span="6">
                                    <el-form-item label="职位类型：">
                                        {{ formData.position_name ? formData.position_name : '--' }}
                                    </el-form-item>
                                </el-col>
                                <el-col :span="6">
                                    <el-form-item label="职位名称：">
                                        {{ formData.title }}
                                    </el-form-item>
                                </el-col>
                            </el-row>
                        </el-form>
                        <el-form-item
                            label="工作地点："
                            label-width="82px"
                            style="width: 678px;"
                        >
                            {{ formData.address_province_name }}
                            {{ formData.address_city_name }}
                            {{ formData.address_county_name }}
                            {{ formData.address_detail_info }}
                        </el-form-item>
                        <el-form-item
                            label="职位描述："
                            label-width="82px"
                            style="width: 678px;"
                        >
                            {{ formData.intro ? formData.intro : '--' }}
                        </el-form-item>
                    </div>
                    <!--职位要求区域-->
                    <div class="form-view">
                        <div class="form-title">
                            职位要求
                        </div>
                        <el-form inline>
                            <el-row>
                                <el-col :span="4">
                                    <el-form-item label="经验：">
                                        {{ formData.type === 1 ? '实习生' : '毕业校招' }}
                                    </el-form-item>
                                </el-col>
                                <el-col :span="4">
                                    <el-form-item label="学历：">
                                        {{ formData.education_level | educationFilter }}
                                    </el-form-item>
                                </el-col>
                            </el-row>
                        </el-form>
                        <el-form>
                            <el-form-item
                                label="薪资详情："
                                style="width: 678px;"
                            >
                                <div v-if="formData.money_time_type === 1">
                                    {{ formData.money_min }} - {{ formData.money_max }} 元/日
                                </div>
                                <div v-if="formData.money_time_type === 2">
                                    {{ formData.money_min / 1000 }} - {{ formData.money_max / 1000 }} K/月
                                </div>
                            </el-form-item>
                            <el-form-item
                                label="职位关键字："
                                label-width="96px"
                                style="width: 678px;"
                            >
                                {{ formData.keyword && formData.keyword.length ? formData.keyword.join('，') : '--' }}
                            </el-form-item>
                            <el-form-item
                                label="职位福利："
                                style="width: 678px;"
                            >
                                {{ formData.benefit && formData.benefit.length ? formData.benefit.join('，') : '--' }}
                            </el-form-item>
                            <el-form-item
                                label="实习要求："
                                style="width: 678px;"
                                v-if="formData.type === 1"
                            >
                                最少实习{{ formData.internship_require_time_num }}{{ formData.internship_require_time_type === 1 ? '天' : '个月' }} {{ formData.work_day_weekly }}天/周
                            </el-form-item>
                            <el-form-item
                                label="毕业时间："
                                style="width: 678px;"
                                v-if="formData.type === 2"
                            >
                                {{ formData.graduate_years ? formData.graduate_years.join('，') : '--' }}
                            </el-form-item>
                        </el-form>
                    </div>
                </el-form>
                <div class="operating-view">
                    <el-button
                        size="medium"
                        v-if="formData.verify !== 1"
                        @click="handleRoute('recruitPostList')"
                    >
                        返回
                    </el-button>
                    <el-button
                        size="medium"
                        v-if="formData.verify === 0"
                        @click="showVerifyDialog(-1)"
                    >
                        不通过
                    </el-button>
                    <el-button
                        size="medium"
                        type="primary"
                        v-if="formData.verify === 0"
                        @click="showVerifyDialog(1)"
                    >
                        通过
                    </el-button>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
import { back } from '@/mixin/back';

export default {
    name: 'RecruitPostDetail',
    mixins: [back],
    components: {},
    data() {
        return {
            recruit_no: '',
            formData: {},
            authResult: {}
        };
    },
    computed: {},
    watch: {},
    filters: {
        educationFilter(val) {
            switch (val) {
                case 1:
                    return '专科';
                case 2:
                    return '本科';
                case 3:
                    return '研究生';
                case 4:
                    return '博士';
                default:
                    return '--';
            }
        },
    },
    mounted() {
        let query = this.$route.query;

        this.$store.commit('SET_HEADER', [{title: "APP后台"}, {title: '工作'}, {title: '人力资源'}, {title: '岗位审核', path: '/student/recruit-post-list'}, {title: '审核'}]);
        this.authResult = this.$route.meta.authResult;
        this.recruit_no = query.recruit_no;
        this.getDetailData();
    },

    methods: {
        /**
         * @description 获取数据
         */
        getDetailData() {
            let params = {
                recruit_no: this.recruit_no
            };

            this.$post('/student/work_recruit%5Cshop_apply%5Cget_audit_detail', params, res => {
                if (res.code === 1) {
                    this.formData = res.data;
                } else {
                    this.$notify({
                        title: '提示',
                        message: res.msg,
                        type: 'warning'
                    });
                }
            });
        },

        /**
         * 路由跳转
         * @param routeName
         * @param query
         */
        handleRoute(routeName, query) {
            this.$router.push({
                name: routeName,
                query
            });
        },

        /**
         * 显示审核操作弹窗
         * @param action -1拒绝 2通过
         */
        async showVerifyDialog(action) {
            if(!this.authResult.auth_verify) {
                this.$notify({
                    title: '提示',
                    message: '请联系管理员添加权限',
                    type: 'warning',
                    duration: 2000
                });
                return false;
            }
            // 通过
            if (action === 1) {
                this.$zdConfirm('是否确认通过该任务的审核？', '审核通过提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(async () => {
                    this.handleVerify(this.recruit_no, action);
                }).catch(() => {});
            } else {
                let reason = await this.$zdPrompt({
                    title: '审核不通过',
                    message: '不通过原因',
                    placeholder: '请输入不通过原因…'
                });

                if(reason) {
                    this.handleVerify(this.recruit_no, action, reason);
                }
            }
        },

        /**
         * 审核
         * @param recruit_no
         * @param verify
         * @param fail_reason
         */
        handleVerify(recruit_no, verify, fail_reason) {
            let params = {
                recruit_no,
                verify,
                fail_reason,
            };

            this.$post('/student/work_recruit%5Cshop_apply%5Cset_audit_status', params, resp => {
                if (resp.code === 1) {
                    this.$notify({
                        title: '提示',
                        message: '操作成功',
                        duration: 2000,
                        type: 'success'
                    });
                    this.getDetailData();
                    this.handleRoute('recruitPostList');
                } else {
                    this.$notify({
                        title: '提示',
                        message: resp.msg,
                        duration: 2000,
                        type: 'warning'
                    });
                }
            });
        }
    }
};
</script>

<style lang="less" scoped>
.wrapper {
    width: 100%;

    .content-wrapper {
        display: flex;
        height: calc(100% - 24px);
        flex-direction: column;
        position: relative;
        margin: 12px;
        background: #fff;
        box-sizing: border-box;
        overflow-x: hidden;
        /*header*/

        .header {
            height: 66px;
            padding-left: 24px;
            box-sizing: border-box;
            box-shadow: 0px -1px 0px 0px #F0F2F5;
            display: flex;
            align-items: center;
            justify-content: space-between;
            border-bottom: 1px solid #F0F2F5;
            flex-shrink: 0;

            .header-title {
                font-size: 18px;
                font-family: PingFangSC-Medium, PingFang SC;
                font-weight: 500;
                color: #333333;
                .project-title {
                    font-size: 14px;
                    font-family: PingFangSC-Regular, PingFang SC;
                    font-weight: 400;
                    color: #333333;
                    margin-left: 12px;
                }
            }
            .option-button {
                display: flex;
                align-items: center;
                .button-item {
                    height: 48px;
                    padding: 0 24px;
                    border-right: 1px solid #F0F2F5;
                    font-size: 14px;
                    font-family: PingFangSC-Medium, PingFang SC;
                    font-weight: 500;
                    color: #666666;
                    display: flex;
                    align-items: center;
                    justify-content: center;
                    cursor: pointer;
                    &.last {
                        border-right: 0;
                        color: #1890FF;
                    }
                    &:hover {
                        background: #F9F9F9;
                        transition: all 0.2s;
                    }
                }
            }
            .back {
                font-size: 14px;
                font-family: PingFangSC-Medium, PingFang SC;
                font-weight: 500;
                color: #333333;
                cursor: pointer;
                margin-right: 24px;
            }
        }
        .form-wrapper {
            overflow-y: auto;
            padding: 24px 56px;
            &::-webkit-scrollbar {
                width: 6px;
            }
            .status-view {
                display: flex;
                flex-direction: column;
                border-bottom: 1px solid #F0F2F5;
                flex-shrink: 0;
                padding-bottom: 24px;
                .status-text {
                    font-size: 16px;
                    font-family: PingFangSC-Medium, PingFang SC;
                    font-weight: 500;
                    &.warning {
                        color: #FFB726;
                    }
                    &.success {
                        color: #2FBDB3;
                    }
                    &.danger {
                        color: #F95B56;
                    }
                }
                .status-desc-text {
                    font-size: 12px;
                    font-family: PingFangSC-Regular, PingFang SC;
                    font-weight: 400;
                    color: #999999;
                    margin-top: 12px;
                }
            }
        }

        .form-view {
            margin-top: 32px;
            border-bottom: 1px solid #F0F2F5;
            .form-title {
                font-size: 16px;
                font-family: PingFangSC-Semibold, PingFang SC;
                font-weight: 600;
                color: #333333;
                margin-bottom: 18px;
            }
        }
        .operating-view {
            padding: 32px 0 52px;
            .el-button {
                width: 120px;
                margin-right: 24px;
            }
        }
    }
    /deep/ .el-form {
        .el-form-item {
            margin-bottom: 6px;
        }
        .el-form-item__label {
            color: #555;
        }
        .bold {
            .el-form-item__label {
                font-size: 14px;
                font-family: PingFangSC-Medium, PingFang SC;
                font-weight: 500;
                color: #333333;
            }
        }
        .el-form-item__content {
            line-height: 24px;
            margin-top: 8px;
            color: #999;
        }
        .is-required {
            .el-form-item__label {
                &:before {
                    content: "*";
                    display: inline-block;
                    color: #F56C6C;
                    margin-right: 4px;
                }
            }
        }
    }
    /deep/ .el-dialog__header {
        padding-top: 10px;
        box-shadow:0 1px 0 0 rgba(233,233,233,1);
        display: flex;
        align-items: center;
        background: #FAFAFA;
        border-radius: 4px 4px 0 0;
        .el-dialog__title {
            font-weight: 500;
            color: #333;
            font-size: 14px;
        }
        .el-icon-close:before {
            color: rgb(194,194,194);
            font-size: 17px;
            font-weight: bold;
        }
        .el-dialog__headerbtn {
            top: 14px;
        }
    }
    .dialog-footer {
        display: flex;
        justify-content: center;
    }
    /deep/ .el-textarea__inner {
        resize: none;
    }
}
</style>
